<?php
include('../../__global.php');

class aj_delColContent extends ml_controller {

    private $uid;
    private $col_id;
    private $pic_id;
    private $rid;

    function initParam() {

        $this->col_id = $this->input('col_id', '', 0);
        $this->pic_id = $this->input('pid', '', 0);
        $this->uid    = $this->__visitor['uid'];
        $this->rid    = $this->input('rid');
    }

    function checkParam() {

        $this->check_referer();
        if ($this->check_permission(ML_PERMISSION_LOGOUT_ONLY)) {
            $this->api_output(ML_RCODE_NOLOGIN);
        }

        if ($this->check_permission(ML_PERMISSION_UNVERIFY_ONLY)) {
            $this->api_output(ML_RCODE_NOACTIVE);
        }

//        if (!ml_tool_picid::is_mlpid($this->pic_id)) {
//            $this->api_output(ML_RCODE_PARAM,'','wrong pid');
//        }


    }

    public function main() {
        /**
         *
         *修改col_info的相关操作
         *statr
         */
        $model=new ml_model_dbCollectionBox();
        $re_model=new ml_model_dbCollectionRe();
        $contentModel=new ml_model_dbContent();
        $data=$model->getColinfo($this->uid, $this->col_id);
        $next_pid_rid=$re_model->get_next_pid($this->uid, $this->col_id);
        $next_pid=$contentModel->get_by_rid($next_pid_rid['rid']);
        
        $data=array_diff($data['col_info'], array($this->pic_id));
        if(!empty($next_pid['pic_id'])){        
            $data=array_merge($data,array($next_pid['pic_id']));
        }
        
        
        $model->updateCol_info($this->uid, $this->col_id, $data);
        /**
         *end
         */

        $model->delContent($this->uid, $this->col_id);      //采集数-1
        $redis=new ml_model_rdsCount();
        $redis->decrColCnt($this->rid);                     //宝贝被采集数-1
        $modelComment=new ml_model_dbCollectionComment();
        $modelComment->delComment($this->rid, $this->col_id, $this->uid); //宝贝转采评论表status=9
        $rs=$re_model->delContent($this->uid,$this->col_id,$this->rid);//关系表status=9
        ml_tool_sendMq::del_atme_in_collect($this->__visitor['uid'] , $this->col_id);
        if(!$rs){
            $this->api_output(ML_RCODE_FAIL,'','fail');
        }
        else{
            $this->api_output(ML_RCODE_SUCC);

        }
    }

}

new aj_delColContent();